package com.example.demoweb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Date 2021/6/20 15:42
 * @Created by wangle
 * @Description
 */
@Controller
public class Requestcontroller {

    @GetMapping("/goto")
    public  String   gotoPage(HttpServletRequest request){

        request.setAttribute("msg","成功了！");
        request.setAttribute("code",200);
        return  "forward:/success";

    }

    @GetMapping("/parameter")
    public  String   testparamerPage(HttpServletRequest request,
                                     Model model,
                                     Map<String ,Object> map,
                                     HttpServletResponse response){


    map.put("n1","aaaa");
    model.addAttribute("n2","bbbb");
    request.setAttribute("n3","ccccc");

        Cookie cookie=new Cookie("n4", "dddd");
        response.addCookie(cookie);

        return  "forward:/success";

    }
    @ResponseBody
    @GetMapping("/success")
    public Map<String ,Object> successPage(
                                           HttpServletRequest request){

        Map<String,Object> map=new HashMap<>();
        map.put("n1",request.getAttribute("n1"));
        map.put("n2",request.getAttribute("n2"));
        map.put("n3",request.getAttribute("n3"));


        return  map;
    }
}
